package com.sayice.coursetable.ui.course.day;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sayice.coursetable.R;
import com.sayice.coursetable.logic.model.Course;
import com.sayice.coursetable.logic.utils.DateUtils;

import java.util.List;

/**
 * 日课程适配器
 */
public class DayCourseAdapter extends RecyclerView.Adapter<DayCourseAdapter.ViewHolder> {
    private final List<Course> courseList;

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView name;
        private final TextView teach;
        private final TextView room;
        private final TextView time;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.name);
            teach = itemView.findViewById(R.id.teach);
            room = itemView.findViewById(R.id.room);
            time = itemView.findViewById(R.id.time);
        }
    }

    public DayCourseAdapter(@NonNull List<Course> courseList) {
        this.courseList = courseList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
        View view = layoutInflater.inflate(R.layout.day_course_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
        Course course = courseList.get(position);
        viewHolder.name.setText(course.name);
        viewHolder.teach.setText(course.teach);
        viewHolder.room.setText(course.room);
        viewHolder.time.setText(DateUtils.toClassTime(course.sectionNum));
    }

    @Override
    public int getItemCount() {
        return courseList.size();
    }
}
